package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CardEmptycard;
import com.ruoyi.system.service.ICardEmptycardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 空卡制作Controller
 *
 * @author ruoyi
 * @date 2025-01-25
 */
@RestController
@RequestMapping("/system/emptycard")
public class CardEmptycardController extends BaseController
{
    @Autowired
    private ICardEmptycardService cardEmptycardService;

    /**
     * 查询空卡制作列表
     */
    @PreAuthorize("@ss.hasPermi('system:emptycard:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardEmptycard cardEmptycard)
    {
        startPage();
        List<CardEmptycard> list = cardEmptycardService.selectCardEmptycardList(cardEmptycard);
        return getDataTable(list);
    }

    /**
     * 导出空卡制作列表
     */
    @PreAuthorize("@ss.hasPermi('system:emptycard:export')")
    @Log(title = "空卡制作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardEmptycard cardEmptycard)
    {
        List<CardEmptycard> list = cardEmptycardService.selectCardEmptycardList(cardEmptycard);
        ExcelUtil<CardEmptycard> util = new ExcelUtil<CardEmptycard>(CardEmptycard.class);
        util.exportExcel(response, list, "空卡制作数据");
    }

    /**
     * 获取空卡制作详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:emptycard:query')")
    @GetMapping(value = "/{inputId}")
    public AjaxResult getInfo(@PathVariable("inputId") Long inputId)
    {
        return success(cardEmptycardService.selectCardEmptycardByInputId(inputId));
    }

    /**
     * 新增空卡制作
     */
    @PreAuthorize("@ss.hasPermi('system:emptycard:add')")
    @Log(title = "空卡制作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardEmptycard cardEmptycard)
    {
        SysUser user = getLoginUser().getUser();
        cardEmptycard.setUserId(user.getUserId());
        cardEmptycard.setDeptId(user.getDeptId());
        cardEmptycard.setUpdateBy(user.getUserName());
        return toAjax(cardEmptycardService.insertCardEmptycard(cardEmptycard));
    }

    /**
     * 修改空卡制作
     */
    @PreAuthorize("@ss.hasPermi('system:emptycard:edit')")
    @Log(title = "空卡制作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CardEmptycard cardEmptycard)
    {
        return toAjax(cardEmptycardService.updateCardEmptycard(cardEmptycard));
    }

    /**
     * 删除空卡制作
     */
    @PreAuthorize("@ss.hasPermi('system:emptycard:remove')")
    @Log(title = "空卡制作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inputIds}")
    public AjaxResult remove(@PathVariable Long[] inputIds)
    {
        return toAjax(cardEmptycardService.deleteCardEmptycardByInputIds(inputIds));
    }
}
